<?php

class DbHandler {
	
	private $hostAndName;
	private $username;
	private $password;
	private $sucess;
	private $dbh;
	
	public function __construct($host, $dbname, $username, $password) {
		$this->hostAndName = "mysql:host=".$host.";dbname=".$dbname;
		$this->username = $username;
		$this->password = $password;
	}
	
	public function connect() {
		try {
    		$this->dbh = new PDO($this->hostAndName, $this->username, $this->password);	
    		$this->sucess = true;
			$msg = 'OK';
			
		} catch (PDOException $e) {
			$this->sucess = false;
			$msg = "Error ".$this->hostAndName;
			$msg = date('d.m.Y h:i:s')." ".$msg;
		}
		return array($this->dbh, $this->sucess, $msg);
	}
	
	public function disconnect() {
		$this->dbh = null;
	}
}

?>